/*
 * @Author: wangyongcun@persagy.com
 * @Date: 2025-03-02 20:26:49
 * @LastEditTime: 2025-03-14 09:39:11
 * @FilePath: \vite-admin\src\store\modules\appSetting.ts
 * @Description:
 *
 */

// 配置信息
import defaultSettings from "@/appSetting";
const settings = useStorage("appSetting", defaultSettings, localStorage);

// 移动端判断
import { breakpointsElement } from '@vueuse/core'
const breakpoints = useBreakpoints(breakpointsElement)

export const useAppSetting = defineStore("appSetting", () => {
  // 移动端判断
  const isMobile = breakpoints.smaller('sm');

  // **主题切换
  const changeTheme = (value: Theme) => {
    settings.value.theme = value;
  }

  // **size切换
  const changeSize = (value: Size) => {
    settings.value.size = value;
  }

  // ** 水印配置
  const changeWatermark = (value: Watermark) => {
    settings.value.watermark = value;
  }

  // ** 菜单配置
  watch(isMobile, (value) => {
    if (value) {
      settings.value.menuConfig = {
        isCollapse: true,
        mode: 'vertical',
      };
    }
  }, { immediate: true });
  const changeMenuConfig = (value: MenuConfig) => {
    settings.value.menuConfig = value;
  }

  // ** 返回
  return {
    ...toRefs(settings.value),
    isMobile,
    changeTheme,
    changeSize,
    changeWatermark,
    changeMenuConfig,
  };
});
